<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			// 1. test() 匹配

			// 2. exec() 执行查找

			var str = "I like Javascript!";

			var re = /\w+/g;

			var arr;

			while ((arr = re.exec(str)) != null) {
				document.write(arr.index + "-" + re.lastIndex + arr + "<br />");
			}


			// String 内置了几个正则方法
			// match()
			var s = "I'm a good boy";
			var re = /boy/i;
			r = s.match(re);
			document.write(r);

			// search
			var s = "I'm a good boy";
			var re = /boy/i;
			r = s.search(re);
			document.write(r);

			// replace
			var str = "I like JavaScript";
			var re = /JavaScript/;
			var newstr = str.replace(re, "JS");
			alert(newstr);

			// split
			var str = "I like JavaScript";
			var re = /\s/;
			var arr = str.split(re, 2);
			alert(arr);
		</script>
	</body>
</html>
